1137A - Skyscrapers - CodeForces Solution


implementation sortings *1600

Please click on ads to support us..

C++ Code:

/*
Problem: 1137A
Date: 22-01-2024 05:19 AM
*/


#include <iostream>
#include <vector>
#include <set>
#include <random>
#include <algorithm>

using namespace std;

int n, m, a[1000][1000];
set<int> cols[1000], rows[1000];
vector<int> vcols[1000], vrows[1000];

int search(vector<int> const& v, int val) {
	int l = 0;
	int r = v.size() - 1;
	while(l <= r) {
		int m = (l + r) / 2;
		if(v[m] == val) {
			return m;
		}else if(v[m] < val) {
			l = m + 1;
		}else {
			r = m - 1;
		}
	}
	return 0;
}

int main() {
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			cin >> a[i][j];

			vrows[i].push_back(a[i][j]);
			vcols[j].push_back(a[i][j]);
//			rows[i].insert(a[i][j]);
//			cols[j].insert(a[i][j]);
		}
	}
	for(int i = 0; i < n; i++) {
		sort(vrows[i].begin(), vrows[i].end());
		vrows[i].erase(unique(vrows[i].begin(), vrows[i].end()), vrows[i].end());
	}
	for(int j = 0; j < m; j++) {
		sort(vcols[j].begin(), vcols[j].end());
		vcols[j].erase(unique(vcols[j].begin(), vcols[j].end()), vcols[j].end());
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			int l = search(vrows[i], a[i][j]);
			int r = search(vcols[j], a[i][j]);
			cout << (max(l, r) + max(vrows[i].size() - l, vcols[j].size() - r)) << " ";
		}
		cout << endl;
	}
}


Comments

Submit
0 Comments
More Questions

1445B - Elimination
1656C - Make Equal With Mod
567A - Lineland Mail
1553A - Digits Sum
1359B - New Theatre Square
766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort